package gupao.concurrency.datasync.task.v1x;

import gupao.concurrency.utils.Utils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.UUID;

@Slf4j
@Component
public class WordProviderMock {

    public Collection<List<String>> queryAllWord(int partitionNum, int totalNum){
        log.info("prepare words...");
        long start = System.currentTimeMillis();
        int x = totalNum / partitionNum;
        int y = totalNum % partitionNum;
        List<List<String>> lists = new ArrayList<>();
        for(int i = 0; i < partitionNum; i++){
            List<String> list = new ArrayList<>();
            for(int k = 0; k < x; k++){
                list.add(UUID.randomUUID().toString());
                Utils.sleepIgnoreExp(1);
            }
            lists.add(list);
        }
        if(y > 0){
            for(int i = 0; i < y; i++){
                int idx = i % partitionNum;
                lists.get(idx).add(UUID.randomUUID().toString());
            }
        }
        log.info("provide word list time cost: {}ms", (System.currentTimeMillis()-start));
        return lists;
    }
}
